/************************************************/
/************************************************/
/*** PART 4.5: APPENDIX FIGURES  ***/
/************************************************/
/************************************************/

/************************************************/
*** SEMIPARAMETRIC ESTIMATION
/************************************************/

	preserve
	
	collapse  bcoleman_ref* ageinm maleshare biat_ethnic baseline_tmale baseline_tage baseline_texperience tmarried baseline_tchildnum ttenured bteyes_sd btraven_sd b_pedagogy b_gms b_idealism b_competence b_modern b_extrinsic b_warmth csize gr1 gr2 grade1 b_schoolid b_classid baseline_tterm braven_sd bmath_std bturk_std urfa refshare b_districtid btsurvey_16_refprop  (mean) male sample1 sample0, by(btname)
	*398

** COLEMAN HOMOPHILY

	global covar3 baseline_tmale baseline_tage baseline_texperience tmarried baseline_tchildnum ttenured bteyes_sd btraven_sd b_gms b_pedagogy b_competence b_modern b_extrinsic b_warmth b_idealism refshare csize urfa male ageinm 

	
	** COMBINE RECEIVED AND PROVIDED
	
	egen bcoleman_ref1_supportall=rowmean(bcoleman_ref1_supportself bcoleman_ref1_support)
	egen bcoleman_ref2_supportall=rowmean(bcoleman_ref2_supportself bcoleman_ref2_support)
	egen bcoleman_ref1_studyall=rowmean(bcoleman_ref1_studyself bcoleman_ref1_study)
	egen bcoleman_ref2_studyall=rowmean(bcoleman_ref2_studyself bcoleman_ref2_study)


	keep if sample1==1
	tab b_schoolid, gen(sch)

	** outlier b_schoolid==214
	drop if b_schoolid==214

	semipar bcoleman_ref1_friend  $covar3 gr1 gr2 sch2-sch73 if sample1==1, nonpar(biat_ethnic) cluster(b_classid) ///
	 ci degree(1) level(95) ytitle(Coleman's Homophily Index (with 95% CIs)) xtitle(Teacher's Ethnic Bias) title("Host Excess Homophily: Friendship") 
	gr_edit .style.editstyle boxstyle(shadestyle(color(white))) editcopy
	graph save hostinfriend, replace
	graph export "$path1/appendix_figureA4a.png", replace
	 
	semipar bcoleman_ref2_friend  $covar3 gr1 gr2 sch2-sch73 if sample1==1, nonpar(biat_ethnic) cluster(b_classid) ///
	 ci degree(1) level(95) ytitle(Coleman's Homophily Index (with 95% CIs)) xtitle(Teacher's Ethnic Bias) title("Refugee Excess Homophily: Friendship") 
	gr_edit .style.editstyle boxstyle(shadestyle(color(white))) editcopy
	graph save refinfriend, replace
	graph export "$path1/appendix_figureA4b.png", replace

	semipar bcoleman_ref1_supportall  $covar3 gr1 gr2 sch2-sch73 if sample1==1, nonpar(biat_ethnic) cluster(b_classid) ///
	 ci degree(1) level(95) ytitle(Coleman's Homophily Index (with 95% CIs)) xtitle(Teacher's Ethnic Bias) title("Host Excess Homophily: Emotional S.") 
	gr_edit .style.editstyle boxstyle(shadestyle(color(white))) editcopy
	graph save hostinsupport, replace
	graph export "$path1/appendix_figureA4c.png", replace
	 
	semipar bcoleman_ref2_supportall  $covar3 gr1 gr2 sch2-sch73 if sample1==1, nonpar(biat_ethnic) cluster(b_classid) ///
	 ci degree(1) level(95) ytitle(Coleman's Homophily Index (with 95% CIs)) xtitle(Teacher's Ethnic Bias) title("Refugee Excess Homophily: Emotional S.") 
	gr_edit .style.editstyle boxstyle(shadestyle(color(white))) editcopy
	graph save refinsupport, replace
	graph export "$path1/appendix_figureA4d.png", replace

	semipar bcoleman_ref1_studyall  $covar3 gr1 gr2 sch2-sch73 if sample1==1, nonpar(biat_ethnic) cluster(b_classid) ///
	 ci degree(1) level(95) ytitle(Coleman's Homophily Index (with 95% CIs)) xtitle(Teacher's Ethnic Bias) title("Host Excess Homophily: Academic S.") 
	gr_edit .style.editstyle boxstyle(shadestyle(color(white))) editcopy
	graph save hostinstudy, replace
	graph export "$path1/appendix_figureA4e.png", replace
	 
	semipar bcoleman_ref2_studyall  $covar3 gr1 gr2 sch2-sch73 if sample1==1, nonpar(biat_ethnic) cluster(b_classid) ///
	 ci degree(1) level(95) ytitle(Coleman's Homophily Index (with 95% CIs)) xtitle(Teacher's Ethnic Bias) title("Refugee Excess Homophily: Academic S.") 
	gr_edit .style.editstyle boxstyle(shadestyle(color(white))) editcopy
	graph save refinstudy, replace
	graph export "$path1/appendix_figureA4f.png", replace


	erase hostinfriend.gph 
	erase refinfriend.gph 
	erase hostinsupport.gph 
	erase refinsupport.gph 
	erase hostinstudy.gph 
	erase refinstudy.gph

	restore

****************************
*** REVERSE CAUSALITY
*******************************

	xi: reg fphysicalbully_sd biat_ethnic $covar1a empathy_treatment i.grade1 i.b_schoolid if refugee==0 & sample1==1, cluster(b_classid)
	estimates store spec1a

	xi: reg fphysicalbully_sd biat_ethnic $covar1a empathy_treatment i.grade1 i.b_schoolid if refugee==1 & sample1==1, cluster(b_classid)
	estimates store spec1b

	xi: reg fverbalbully_sd biat_ethnic $covar1a empathy_treatment i.grade1 i.b_schoolid if refugee==0 & sample1==1, cluster(b_classid)
	estimates store spec2a

	xi: reg fverbalbully_sd biat_ethnic $covar1a empathy_treatment i.grade1 i.b_schoolid if refugee==1 & sample1==1, cluster(b_classid)
	estimates store spec2b

	xi: reg ftemper_sd biat_ethnic $covar1a empathy_treatment i.grade1 i.b_schoolid if refugee==0 & sample1==1, cluster(b_classid)
	estimates store spec3a

	xi: reg ftemper_sd biat_ethnic $covar1a empathy_treatment i.grade1 i.b_schoolid if refugee==1 & sample1==1, cluster(b_classid)
	estimates store spec3b


	** COEFFICIENT PLOTS 

	#delimit ;
	coefplot
	(spec1a, keep(biat_ethnic)) 
	(spec2a, keep(biat_ethnic))
	(spec3a, keep(biat_ethnic))
	|| 
	(spec1b, keep(biat_ethnic)) 
	(spec2b, keep(biat_ethnic))
	(spec3b, keep(biat_ethnic))

	, horizontal  xline(0) xscale(range (-0.5 0.5)) mlabel format(%8.2f)  mlabposition(12) mlabgap(*2) mlabcolor(navy) ciopts(recast(rcap) color(navy))  color(navy) citop color(navy)
	xtitle(Point Estimates with 95% CIs, margin(0 -40 0 0))  
	byopts(legend(off)
	graphregion(color(white))) bgcolor(white)
	xline(0, lcolor(black))
	ylabel(0.75 "Physically Aggressive"  1.00 "Verbally Disruptive" 1.25 "Short-Tempered")
	bylabels("Host" "Refugee")
	subtitle(,color(white) bcolor(navy))
	;
	#delimit cr
	graph export "$path1/appendix_figureA5.png", replace

